﻿using System.Collections.Generic;
using Qask.Data.Core;

namespace Qask.Service.Core
{
    public class AccountService : IAccountService
    {
        private readonly IAccountRepository _accountRepository;

        public AccountService(IAccountRepository accountRepository)
        {
            _accountRepository = accountRepository;
        }

        public IEnumerable<TimeZoneViewModel> GetTimezones()
        {
            var timezones = _accountRepository.GetTimezones();
            return CustomMapper.Map<TimeZone, TimeZoneViewModel>(timezones);
        }

        public int GetTimeZoneByUserId(string userId)
        {
            return _accountRepository.GetTimeZoneByUserId(userId);
        }

        public AspNetUserModel UpdateTimeZone(AspNetUserModel updatedUserModel)
        {
            AspNetUser user = CustomMapper.Map<AspNetUserModel, AspNetUser>(updatedUserModel);
            user = _accountRepository.UpdateUserTimeZone(user);

            return CustomMapper.Map<AspNetUser, AspNetUserModel>(user);
        }
    }
}
